const cacheName = 'my-web-app-cache'
const filesToCache = [
  '/',
  '/index.html',
  '/style.css',
  '/path/to/icon.png'
]

self.addEventListener('install', (event) => {
  event.waitUntil(
    caches.open(cacheName).then((cache) => {
      return cache.addAll(filesToCache)
    })
  )
})

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then((response) => {
      return response || fetch(event.request)
    })
  )
})
